#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int m, p;

struct Node {
    int l, r, v;
}tr[N * 4];

void pushup(int u) {
    tr[u].v = max(tr[u << 1].v, tr[u << 1 | 1].v);
}

void bulid(int u, int l, int r) {
    tr[u].l = l, tr[u].r = r;
    if (l == r) return ;
    int mid = l + r >> 1;
    bulid(u << 1, l, mid), bulid(u << 1 | 1, mid + 1, r); 
}

void modify(int u, int x, int v) {
    if (tr[u].l == x && tr[u]. r == x) tr[u].v = v;
    else {
        int mid = tr[u].l + tr[u].r >> 1;
        if (x <= mid) modify(u << 1, x, v);
        else modify(u << 1 | 1, x, v);
        pushup(u);
    }
}

int query(int u, int l, int r) {
    if (tr[u].l >= l && tr[u].r <= r) return tr[u].v;
    
    int mid = tr[u].l + tr[u].r >> 1;
    int v = 0;
    if (l <= mid) v = query(u << 1, l, r);
    if (r > mid) v = max(v, query(u << 1 | 1, l, r));
    
    return v;
}

int main() {
    cin >> m >> p;
    bulid(1, 1, m);
    int n = 0, last = 0;
    
    while (m -- ) {
        char op[2];
        int x;
        
        scanf("%s%d", op, &x);
        
        if (op[0] == 'A')  {
            modify(1, n + 1, (last + x) % p);
            n ++ ;
        }
        else {
            last = query(1, n - x + 1, n);
            printf("%d\n", last);
        }
    }
    
    return 0;
}